<?php
namespace logInPage;

class LogInPage{
		
	private static $username = 'username'; 
	private static $password = 'password';
	private static $checkbox = 'rememberMe';
	private static $logInButton = 'logInButton';
	private static $message = "";
	
	public function getUsername(){
		if(isset($_POST[self::$username])){	
		return $_POST[self::$username];
		}
	}
	public function getPassword(){
		if(isset($_POST[self::$password]))
		return $_POST[self::$password];
	}
	public function getCheckbox(){
		if(isset($_POST[self::$checkbox]))
		return TRUE;
	}
	
	public function logInButton(){
		if(isset($_POST[self::$logInButton])){
			if($this->viewCheck() == TRUE){
				return TRUE;		
			}
		}
			return FALSE;
	}
	
	private function viewCheck(){
		if(empty($_POST[self::$username])){
			self::$message = "Användarnamn Saknas! ";
			return FALSE;
		}else if(empty($_POST[self::$password])){
			self::$message = "Lösenord saknas! ";
			return FALSE;
		}
		return TRUE;
	}
	
	public function loggedInHeader(){
		$header = '
				<div id="header">
				<h1>INLOGGAD SOM ' . $_POST[self::$username] . '</h1>
				</div>
				';
		
		return $header;
	}
	public function loggedOutHeader(){
		$header = '
				<div id="header">
				<h1>INTE INLOGGAD!</h1>
				</div>
				';
		return $header;
	}
	
	public function getPage(){
		
		$usernamevalue = $this->getUsernameValue();
		$logInHtml = self::$message;     
		$logInHtml .= "
					<div id='centercontent'>
					<form class='form-inline' action='index.php?attempt' method='post' role='form'>
						<div class='form-group'>
					    	<label class='sr-only' for='Username'>Username</label>
					    	<input type='text' class='form-control' name='username' id='Username' value='$usernamevalue' placeholder='Användarnamn'>
					  	</div>
					  	<div class='form-group'>
					    	<label class='sr-only' for='Lösenord'>Lösenord</label>
					    	<input type='password' class='form-control' name='password' placeholder='Lösenord'>
					  	</div>
					  	<div class='checkbox'>
					    <label>
					      <input name='rememberMe' type='checkbox'> Kom ihåg mej
					    </label>
					  	</div>
						<button id='LogInButton' name='logInButton'; type='submit' class='btn btn-default'>Logga In</button>
					</form>
					</div>
			 		";			
		return $logInHtml;
	}	
	
	private function getUsernameValue(){
		$usernamevalue = '';
		if(isset($_POST[self::$username])){
			$usernamevalue =$_POST[self::$username]; 
		}
		return $usernamevalue;
	}
}


